﻿
@{
    Layout = null;
}
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>登录</title>
    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/css/style.css" rel="stylesheet">
    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/vendor/toastr/toastr.min.css" rel="stylesheet" />
</head>
<body>
    <div class="login_bg">
        <div class="login_box center flex">
           @* <img src="/img/logo4.png" class="login-logo">
            <p class="login-logo-1">江&nbsp;汉&nbsp;平&nbsp;原&nbsp;智&nbsp;慧&nbsp;水&nbsp;利&nbsp;平&nbsp;台</p>*@
            <div class="left"></div>
            <div class="right">


                <div class="switch">
                    <span class="active" onclick="tabs(this,1)">账密登录</span><span onclick="tabs(this,0)">扫码登录</span>
                </div>
                <div class="option">
                    <input type="text" id="a" class="input-index mt-32" placeholder="账号" required>
                    <input type="password" id="b" class="input-index mt-21" placeholder="密码" required>
                    <input type="text" id="verifyCode" class="input-index mt-21" placeholder="验证码" required>
                    <div class="mt-21"><span style="vertical-align: middle;">验证码：</span><img style="width:80px; height:40px; vertical-align: middle;" id="code" /></div>
                    <input type="button" class="login mt-21" value="登录" id="login">
                </div>
                <div class="option">
                    <img src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/img/code.png" class="code">
                </div>

                <input type="hidden" id="codeToken" value=""/>
            </div>
        </div>
        <div class="footer">
          
        </div>
    </div>


    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/js/jquery-1.10.2.min.js"></script>

    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/vendor/toastr/toastr.min.js"></script>

    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/js/Notic.js"></script>
    <script>

        var return_url = "@Html.Raw(Context.Request.Query["return_url"])";
        return_url = decodeURIComponent(return_url);
        if (return_url != null && return_url != undefined && return_url != ""){
            var pathHost = return_url.split("//")[1];
            var fIndex = pathHost.indexOf("/")
            var lastPath = pathHost.substr(fIndex);
            return_url = window.location.protocol + "//" + window.location.host + "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + lastPath;
        }
        
        getGetVerifyCode();

        console.log(return_url);

        $("#login").click(function () {
            Login($("#login"));
        });

        $("#code").click(function(){
            getGetVerifyCode();
        })

        function Login(obj) {

            var loginName = $("#a").val();
            var passWord = $("#b").val();
            var verifyCode = $("#verifyCode").val();

            if (verifyCode == "") {
                Notic('error', "验证码不能为空");
                return;
            }

            if (a == "")
            {
                Notic('error', "用户名不能为空");
                return;
            }

            if (b == "")
            {
                Notic('error', "密码不能为空");
                return;
            }

            if (obj != null) {
                $(obj).attr("disabled", "disabled");
                $(obj).val("登录中");
            }
            $.ajax({
                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Home/LoginDo",
                data: { "loginName": loginName, "passWord": passWord, "codeToken": $("#codeToken").val(), "verifyCode": verifyCode, "returnUrl": return_url },
                dataType: "json",
                type:"post",
                success: function (data)
                {
                    console.log(data);

                    if (data.IsError)
                    {
                        Notic('error', data.Message);
                        if (obj != null)
                        {
                            $(obj).removeAttr("disabled");
                            $(obj).val("登录");

                        }
                    }
                    else
                    {
                        location = data.Result;
                    }
                   
                },
                error: function (data) {


                }
            });


        }

        function tabs(obj, type) {
            $tab = $(obj);
            var index = $tab.index();
            $tabList = $(".option");
            if (type == 0) {
                $tabList.hide();
                $tabList.eq(index).show();
                $tab.addClass("active");
                $tab.siblings("span").removeClass("active");
                $tab.attr('onClick', "tabs(this,1)");
                $tab.siblings("span").attr('onClick', "tabs(this,0)");
            } else return;
        }

        function getGetVerifyCode(){
            $.ajax({
                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Home/GetVerifyCode",
                data: {},
                dataType: "json",
                type: "get",
                success: function (data) {
                    $("#code").attr("src", data.result.imgCode);
                    $("#codeToken").val(data.result.codeToken);
                },
                error: function (data) {


                }
            });
        }

    </script>


</body>
</html>
